Skip to content

Add AI binding support for pi - #123

Merged
Maximo-Guk merged 6 commits into
mainfrom
maximo/add-ai-binding-support-for-pi
Aug 18, 2026
Merged

Add AI binding support for pi#123
Maximo-Guk merged 6 commits into
mainfrom
maximo/add-ai-binding-support-for-pi

Conversation

@Maximo-Guk

@Maximo-Guk Maximo-Guk commented Aug 10, 2026

Copy link
Copy Markdown
Member

Why?
We want to enable users to use AI gateway without needing to provide an API token ( which puts them at risk of credential expiry, rotation, etc ) and makes them need to visit the dashboard just to provision a token during the deploy flow.

How?

Workers AI Gateway can now be accessed over the AI binding!

AI.fetch(https://workers-binding.ai/ai-gateway/gateways/platform-gateway/*)

How was this tested?

You can test it with the updated deploy flow which is based off this branches head https://gadgets-deploy.gadgets-staging.workers.dev/deploy ( notice you don't need to provision an api token ), and also locally.

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

This comment was marked as resolved.

Comment thread docs/ai-gateway-billing.md
@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 59cd827 to 595d66d Compare August 10, 2026 15:56
@ask-bonk

This comment was marked as resolved.

@ask-bonk

This comment was marked as resolved.

@kentonv

kentonv commented Aug 11, 2026

Copy link
Copy Markdown
Member

Looks like upstream PR was merged, shall we update to use that?

@Maximo-Guk

Copy link
Copy Markdown
Member Author

Just waiting on a PI release before we can use the upstreamed changes, I'll put up a PR to update once it gets released.

The vendored transport changes in this PR are identical to what got merged in to PI, I would like to get this out so we can start battle testing what we upstreamed in to PI.

@Maximo-Guk
Maximo-Guk marked this pull request as draft August 13, 2026 20:07
@Maximo-Guk

Copy link
Copy Markdown
Member Author

Drafting this for the time being as I work through on updating the PI implementation to be smarter & more efficient

@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 595d66d to 24fbea1 Compare August 14, 2026 14:51
@github-actions github-actions Bot added kernel Changes to the Workshop kernel delivery Changes to CI or release delivery labels Aug 14, 2026
@ask-bonk

This comment was marked as resolved.

@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 24fbea1 to 0672c92 Compare August 14, 2026 14:57
@ask-bonk

This comment was marked as resolved.

@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch 2 times, most recently from 9b54ad4 to f8704a2 Compare August 15, 2026 02:19
@ask-bonk

This comment was marked as resolved.

@ask-bonk

This comment was marked as resolved.

@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from f8704a2 to 6f18507 Compare August 15, 2026 20:17
@ask-bonk

This comment was marked as resolved.

@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 6f18507 to 976a0e7 Compare August 15, 2026 20:44
@ask-bonk

This comment was marked as resolved.

@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 976a0e7 to 00d7293 Compare August 18, 2026 02:30
@ask-bonk

ask-bonk Bot commented Aug 18, 2026

Copy link
Copy Markdown

github run

@ask-bonk

ask-bonk Bot commented Aug 18, 2026

Copy link
Copy Markdown

@Maximo-Guk Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@github-actions

Copy link
Copy Markdown

Preview: pr123-maximo-add-ai-3d199549

https://pr123-maximo-add-ai-3d199549-router.cloudflare-os-previews.workers.dev

Dashboard · deleted when this PR closes

@Maximo-Guk

Copy link
Copy Markdown
Member Author

bonk break glass

@github-actions github-actions Bot added the bonk-break-glass Skip automatic Bonk PR review label Aug 18, 2026
@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 00d7293 to 945eb5e Compare August 18, 2026 02:42
@Maximo-Guk
Maximo-Guk marked this pull request as ready for review August 18, 2026 02:51
@Maximo-Guk
Maximo-Guk requested a review from kentonv August 18, 2026 15:38
Comment thread scripts/preview/staging-config.ts
Comment thread packages/workshop-backend/src/ai-models.ts Outdated
Comment thread packages/workshop-backend/src/ai-gateway.ts

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Maximo-Guk and others added 5 commits August 18, 2026 14:10
…ays rides the gateway

The WAI knobs existed because Workers AI originally ran on the account-local
WORKERS_AI binding, which can only name same-account gateways; a cross-account
CF_AI_GATEWAY (the internal production shape) therefore needed an escape
hatch. Workers AI has since moved to ordinary gateway routes
(.../{account}/{gateway}/workers-ai/v1), which work cross-account over
HTTPS+token exactly like anthropic/openai -- so the escape hatch no longer
pays for its config surface.
Binding-routed gateway traffic went through gateway().run(), the
universal endpoint's [{provider, endpoint, headers, query}] envelope,
which a vendored shim built by splicing the request body into a JSON
string. The gateway also serves its provider-native passthrough over the
AI binding at /ai-gateway/gateways/{gateway}/{provider}/... -- the HTTPS
path minus the account id, since the binding channel carries identity --
and that route accepts exactly the requests pi's API impls already
produce.

So there is nothing left to translate. Binding-routed models take the
binding host as their gateway root and pi's fetch option is the binding's
own fetch, unwrapped; the envelope, the splice, the JSON-object scanner
and the whole vendored ai-gateway-binding-fetch module go away. Method,
headers, query string and the body stream ride through untouched, so
multi-MB prompt bodies are never copied in the isolate.

Google keeps its HTTPS root automatically: `binding` is resolved per
provider, and bindingFor() returns undefined for google (its adapter
can't take a custom fetch). cf-aig-authorization now reaches the gateway,
which recognizes the pre-authentication sentinel and strips it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Trim and lowercase the value once on each side, so a stray " False " opts
out instead of reading as unset and silently picking the other transport.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 5acb819 to 200665a Compare August 18, 2026 20:28
@Maximo-Guk

Copy link
Copy Markdown
Member Author

bonk break glass

… Workers AI isn't recommended ( breaks toMarkDown() )
@Maximo-Guk
Maximo-Guk force-pushed the maximo/add-ai-binding-support-for-pi branch from 200665a to 5c09db8 Compare August 18, 2026 20:58
@Maximo-Guk
Maximo-Guk merged commit 8b9fd81 into main Aug 18, 2026
12 checks passed
@Maximo-Guk
Maximo-Guk deleted the maximo/add-ai-binding-support-for-pi branch August 18, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bonk-break-glass Skip automatic Bonk PR review delivery Changes to CI or release delivery kernel Changes to the Workshop kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants